package com.leantech.android.browser.dialog

import android.content.Context
import android.view.ViewGroup
import com.leantech.android.browser.R
import com.leantech.android.browser.databinding.DialogMessageConfirmBinding
import com.leantech.android.browser.utils.onThrottleClick
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.widget.dialog.QMUIBaseDialog

class MessageConfirmDialog(
    context: Context,
    private val onSure: () -> Unit = {}
) : QMUIBaseDialog(context, R.style.MessageDialogStyle) {


    private var title: String? = null
    private var content: String? = null
    private var contentChar: CharSequence? = null

    private val binding: DialogMessageConfirmBinding =
        DialogMessageConfirmBinding.inflate(layoutInflater)

    init {
        setSkinManager(QMUISkinManager.defaultInstance(context))
        setContentView(
            binding.root, ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
            )
        )

        binding.btnSure.onThrottleClick {
            onSure()
            dismiss()
        }

        binding.btnCancel.onThrottleClick {
            dismiss()
        }
    }

    fun setTitle(title: String) = apply {
        this.title = title
    }

    fun setContent(content: String) = apply {
        this.content = content
    }

    fun setContentChar(contentChar: CharSequence) = apply {
        this.contentChar = contentChar
    }

    fun show(isCharSequence: Boolean = false){
        binding.title.text = title
        if(isCharSequence){
            binding.content.text = contentChar
        }else{
            binding.content.text = content
        }
        show()
    }

    override fun show() {
        super.show()
    }
}
